export default {
  increment: (state) => {
    const obj = state
    obj.count += 1
  },
  decrement: (state) => {
    const obj = state
    obj.count -= 1
  },
  saveUser: (state, user) => {
    state.user = user;
  },
  saveProductId: (state, productId) => {
    state.productId = productId;
  },
  saveLocatePage: (state, locatePage) => {
    state.locatePage = locatePage
  },
  saveRoomInfo: (state, room) => {
    state.roomInf = room
  },
  saveLeaseInfo: (state, leaseInfo) => {
    state.leaseInfo = leaseInfo
  },
  saveTravelId: (state, travelId) => {
    state.travelId = travelId;
  },
  saveLocate: (state, locate) => {
    console.log(locate);
    state.latitude = locate.split(',')[0];
    state.longitude = locate.split(',')[1];
  },
  addCart: (state, item) => {
    let isFirstGood = true;
    state.cart.map(function (_item) {
      if (_item.id === item.id) {
        isFirstGood = false;
        _item.amount += (item.amount === undefined ? 1 : item.amount);
      }
    });
    if (isFirstGood) {
      state.cart.push(item);
    }
  },
  removeCart: (state, _item) => {
    state.cart.splice(state.cart.findIndex(item => {
      return item === _item
    }), 1);
  },
  clearCart: (state) => {
    state.cart.length = 0;
  },
  clearGoodsTotal: (state) => {
    state.goodsTotal = {
      totalNum: 0,
      totalPrice: 0
    }
  },
  goodsTotal: (state, goodsTotal) => {
    state.goodsTotal = goodsTotal;
  },
  saveShop: (state, shop) => {
    state.shop = shop;
  },
  saveResult: (state, result) => {
    state.result = result;
  },
  addSubmitGoods: (state, submitGoods) => {
    state.submitGoods = submitGoods;
  },
  saveCheckTransactionId: (state, id) => {
    state.checkTransactionId = id;
  },
  saveOrderId: (state, orderId) => {
    state.orderId = orderId;
  },
  saveBorrow: (state, borrow) => {
    state.borrow = borrow;
  },
  setPaySpinning: (state, blon) => {
    state.paySpinning = blon;
  },
  savePayinfo: (state, payInfo) => {
    state.payInfo = payInfo;
  },
  saveShowLandscape: (state, showLandscape) => {
    state.showLandscape = showLandscape;
  }
}